[1] 0.1
[1] 42
[1] -1e+07
Simple
Free
Flexible
Trendy
Open a new R script file (File > New File > R Script)
Console
Console
Script
Console
Script
Tracking panel
Console
Script
Tracking panel
Multipurpose panel
Check files in your computer, see plots, manage packages, read help section of a function.
Console
Script
Tracking panel
Multipurpose panel
Caution
Write everything you do in scripts to avoid loosing your work.
Tip
Solving errors is an important skill to learn.
Tip
Comment your script to help you remember what you have done.
Complex type
[1] 1 3 5 7 9
$name
[1] "John Doe"
$age
[1] "40"
$skills
[1] "sing" "dance" "run"
$glasses
[1] FALSE
Complex type
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
[,1] [,2] [,3]
[1,] "one" "1" "4"
[2,] "two" "2" "5"
[3,] "three" "3" "6"
Name Age IsStudent
1 John 25 TRUE
2 Jane 30 FALSE
Note
These are the basic complex types. It exists a lot of different complex objects which mix all these basic objects.
if, else, TRUE, FALSE)Tip
Avoid random names such as var1, var2. Use significant names: gene_list, nb_elements
The name of the object followed by the assignment symbol and the value.
You can use operators on objects to modify them. Depending on the object format, operators have different behaviors and some are forbidden.
Exercise
Correction
Exercise
Try to raise errors using operators.
function_name(object, parameter1 = ..., parameter2 = ...)help, ? or F1)Note
Some functions are in the default installation of R. Other functions come from packages. You can also create your own functions.
vector construction
c() Concatenate function1:10 Vector with numbers from 1 to 10vector construction
c() Concatenate function1:10 Vector with numbers from 1 to 10Extra
seq Create a sequence of numbersrep Repeat elements several timesrunif Simulate random numbers from Uniform distribution. Same for rnorm, rpois…Instructions
vector withe 7 numeric valuesvector with 7 character valuesManipulation
Using index/position between []
Characterization
length() Number of elements in the vectornames() Get or set the names of the vector’s value[1] 15
[1] 8 15 16
[1] 4 14 3 9 23 42
[1] 6
NULL
[1] "frank" "henry" "philip" "steve" "tom" "francis"
philip
3
Manipulation
sort() Sort a vectorsample() Shuffle a vectorrev() Reverse a vector frank henry philip steve tom francis
4 14 3 9 23 42
philip frank steve henry tom francis
3 4 9 14 23 42
philip frank
1 2 3 3 4 4 5 6 7 8
steve henry tom francis
9 9 10 14 23 42
francis tom steve philip henry frank
42 23 9 3 14 4
[1] 4 1 7 2 6 5 8 3 9 10
Extra
sort()/sample() Explore extra parametersorder() Get the index of the sorted elementsExploration
head()/tail() Print the first/last valuessummary() Summary statisticsmin()/max()/mean()/median()/var() Minimum, maximum, average, median, variancesum Sum of the vector’s values[1] "sampA" "sampB"
Min. 1st Qu. Median Mean 3rd Qu. Max.
3.00 5.25 11.50 15.83 20.75 42.00
[1] 15.83333
[1] 3
Extra
log/log2/log10 Logarithm functionssqrt Square-root functionArithmetic operators
frank henry philip steve tom francis
6 16 5 11 25 44
frank henry philip steve tom francis
16 56 12 36 92 168
frank henry philip steve tom francis
0 0 0 0 0 0
frank henry philip steve tom francis
4.00 7.00 1.00 2.25 4.60 7.00
Instructions